package com.xs.project.common;

import lombok.Data;

@Data
public class Result<T> {
    private Integer status;
    private String message;
    private T data;
    private Integer total;

    public static <T> Result<T> success(T t) {
        Result<T> result = new Result<>();
        result.setStatus(200);
        result.setMessage("success");
        result.setData(t);
        return result;
    }

    public static <T> Result<T> success(T t,int total) {
        Result<T> result = new Result<>();
        result.setStatus(200);
        result.setMessage("success");
        result.setData(t);
        result.setTotal(total);
        return result;
    }

    public static <T> Result<T> fail(String message) {
        Result<T> result = new Result<>();
        result.setStatus(-1);
        result.setMessage(message);
        return result;
    }
    public static <T> Result<T> fail(String message,T t) {
        Result<T> result = new Result<>();
        result.setStatus(-1);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> fail(HttpResp httpResp) {
        Result<T> result = new Result<>();
        result.setStatus(httpResp.code);
        result.setMessage(httpResp.msg);
        return result;
    }

    public static <T> Result<T> fail(String message,Integer status) {
        Result<T> result = new Result<>();
        result.setStatus(status);
        result.setMessage(message);
        return result;
    }
}
